package com.faithbj.common.dao.impl;

import java.lang.reflect.Method;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.faithbj.common.dao.UserLogInfoDao;
import com.faithbj.common.model.UserLogInfo;

/**
 * @author jrn E-mail: rinanjin@gmail.com
 * @version 0.1 
 * 创建时间：2012-6-26 下午08:52:47
 * 类说明
 */
@Repository("userLogInfoDao")
public class UserLogInfoDaoImpl extends BaseDaoImpl<UserLogInfo, String> implements UserLogInfoDao
{
	public String save(UserLogInfo entity)
	{
		Assert.notNull(entity, "entity is required");
		Session session = getSessionFactory().openSession();
		try
		{
			Method[] methods = entity.getClass().getMethods();
			for (Method mt : methods)
			{
				if (StringUtils.equals("onSave", mt.getName()))
				{
					Method localMethod = entity.getClass().getMethod(
							"onSave", new Class[0]);
					if (null != localMethod)
						localMethod.invoke(entity, new Object[0]);
					break;
				}
			}
			
			String id = (String) session.save(entity);
			session.flush();
			session.close();
			return id;
		} catch (Exception localException)
		{
			localException.printStackTrace();
			return null;
		}
//		return (PK) getSession().save(entity);
	}
}
